//
//  CZTextAttachment.swift
//  weibo
//
//  Created by Apple on 16/3/21.
//  Copyright © 2016年 KY. All rights reserved.
//

import UIKit

class CZTextAttachment: NSTextAttachment {
    //  添加图片模型属性
    var emoticon: CZEmoticon?
    
    func attributedStringWithEmoticon(emoticon: CZEmoticon, font: UIFont) -> NSAttributedString {
        
        //  1.生成图片
        let image = UIImage(named: emoticon.fullPath!)
        //  2.通过Attachment对象设置自身属性的数据
        self.emoticon = emoticon
        self.image = image
        //  修改表情大小跟文字行高一样大
        let height = font.lineHeight
        //  图片表情往下-3.5
        self.bounds = CGRect(x: 0, y: -3.5, width: height, height: height)
        //  3.生成富文本
        let attributedStr = NSAttributedString(attachment:self)
        return attributedStr
    }
}
